from django.db import models

# Create your models here.


class SiteName(models.Model):  # 网站名

    name = models.CharField(max_length=50)

    url = models.URLField(max_length=500)  # 网站的域名

    def __str__(self):

        return self.name


class FilmType(models.Model):  # 电影类型

    fim_type = models.CharField(max_length=50)

    def __str__(self):

        return self.fim_type


class Director(models.Model):  # 导演

    name = models.CharField(max_length=50)

    def __str__(self):

        return self.name


class Actor(models.Model):  # 演员

    name = models.CharField(max_length=50)

    def __str__(self):

        return self.name


class State(models.Model):  # 拍摄国家

    name = models.CharField(max_length=50)

    def __str__(self):

        return self.name


class Language(models.Model):  # 语言

    name = models.CharField(max_length=50)

    def __str__(self):

        return self.name


class ReleaseState(models.Model):  # 上映国家

    name = models.CharField(max_length=50)

    def __str__(self):

        return self.name


class FilmName(models.Model):  # 电影名称

    name = models.CharField(max_length=50)  # 电影名称

    def __str__(self):

        return self.name


class Film(models.Model):  # 电影

    name = models.ForeignKey(FilmName,on_delete=models.CASCADE)

    other_name = models.CharField(max_length=50)  # 电影别名

    director = models.ManyToManyField(Director)  # 多对多关联导演

    actor = models.ManyToManyField(Actor)  # 多对多关联演员

    state = models.ManyToManyField(State)  # 多对多关联地区

    release_state = models.ManyToManyField(ReleaseState,through='ReleaseTime')  # 多对多关系抛出

    site_name= models.ManyToManyField(SiteName,through='FilmInSite')  # 多对多关系抛出

    film_type = models.ManyToManyField(FilmType)

    intro = models.TextField()  # 简介


class FilmInSite(models.Model):  # Film和SiteName多对多关系

    film = models.ForeignKey(Film,on_delete=models.CASCADE)

    site_name = models.ForeignKey(SiteName,on_delete=models.CASCADE)


class ReleaseTime(models.Model):  # 上映时间

    release_state = models.ForeignKey(Film, on_delete=models.CASCADE)

    film = models.ForeignKey(ReleaseState,on_delete=models.CASCADE)

    release_time = models.DateTimeField()


class FilmUrl(models.Model):  # 电影播放链接

    film_in_site = models.ForeignKey(FilmInSite,on_delete=models.CASCADE)

    url = models.URLField(max_length=500)

    name=  models.CharField(max_length=50)

    layout = models.CharField(max_length=50)

    write_time = models.DateTimeField(auto_now_add=True)

